package com.zhoug.plugin.android.constgenerator.utils;


import com.zhoug.plugin.android.constgenerator.beans.ConstField;

import javax.swing.table.DefaultTableModel;
import java.util.List;

public class ActionUtils {
    private final static String[] HEADERS = {"FieldName", "value", "name"};

    public static DefaultTableModel getTableModel(List<ConstField> constFields) {
        DefaultTableModel tableModel = new DefaultTableModel();
        int size = constFields.size();
        Object[][] cellData = new Object[size][3];
        for (int i = 0; i < size ; i++) {
            ConstField constField = constFields.get(i);
            cellData[i][0] = constField.getFieldName();
            cellData[i][1] = constField.getValue();
            cellData[i][2] = constField.getName();
        }

        tableModel = new DefaultTableModel(cellData, HEADERS) {
            final Class[] typeArray = {Object.class, Object.class, Object.class};

            @Override
            public boolean isCellEditable(int row, int column) {
                return column == 0;//是否可以编辑
            }

            @SuppressWarnings("rawtypes")
            public Class getColumnClass(int column) {
                return typeArray[column];
            }


        };
        return tableModel;
    }
}
